<?php

namespace App\Admin\Controllers;

use App\Models\UserAddress;
use Encore\Admin\Controllers\AdminController as Controller;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class UserAddressController extends Controller
{
    protected $title = "用户地址管理";

    protected function grid()
    {
        $grid = new Grid(new UserAddress);

        $grid->id('ID');
        $grid->customer_id('顾客ID');
        $grid->province('省');
        $grid->city('市');
        $grid->district('县/区');
        $grid->address('详细地址');
        $grid->contact_name('联系人');
        $grid->contact_phone('联系电话');
        $grid->zip('邮编');
        $grid->is_default('是否默认');
        $grid->created_at(__('Created at'));
        $grid->updated_at(__('Updated at'));

        return $grid;
    }

    protected function detail($id)
    {
        $show = new Show(UserAddress::findOrFail($id));

        $show->id('ID');
        $show->customer_id('顾客ID');
        $show->province('省');
        $show->city('市');
        $show->district('县/区');
        $show->address('详细地址');
        $show->contact_name('联系人');
        $show->contact_phone('联系电话');
        $show->zip('邮编');
        $show->is_default('是否默认');
        $show->created_at(__('Created at'));
        $show->updated_at(__('Updated at'));

        return $show;
    }

    protected function form()
    {
        $form = new Form(new UserAddress);

        $form->number('customer_id', '顾客ID');
        $form->distpicker([
            'province_id' => '省份',
            'city_id' => '市',
            'district_id' => '区'
        ], '地域选择');
        $form->textarea('address', '详细地址');
        $form->text('contact_name', '联系人');
        $form->text('contact_phone', '联系电话');
        $form->number('zip', '邮编');
        $form->switch('is_default', '是否默认')->default(1);

        return $form;
    }
}
